/*
 * @Description:
 * @Version: 2.0
 * @Autor: wushiyang
 * @Date: 2022-06-07 10:07:53
 * @LastEditors: wushiyang
 * @LastEditTime: 2022-06-07 10:26:15
 */
import * as storage from "local-storage";
import { PROJECT_CACHE } from "./constant";

export function setValue(key, value) {
    storage.set(key, value);
}

export function getValue(key) {
    return storage.get(key);
}

export function deleteValue(key) {
    storage.remove(key);
}

export function clear() {
    storage.clear();
}

export function clearProject() {
    const regex = new RegExp(`${PROJECT_CACHE}\\d+`);
    for (let index = 0; index < window.localStorage.length; index++) {
        const key = window.localStorage.key(index);
        if (regex.test(key)) {
            storage.remove(key);
        }
    }
}
